package com.young.android.view;

import java.util.ArrayList;


import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.young.android.R;
import com.young.android.entity.Resource;

/**
 * RSS资源适配器
 * 
 * @author Young
 * 
 */
public class ResourceAdapter extends BaseAdapter {

    private ArrayList<Resource> resourceList;
    private Context context;

    public ResourceAdapter(ArrayList<Resource> resourceList, Context context) {
        this.resourceList = resourceList;
        this.context = context;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return resourceList.size();
    }

    @Override
    public Resource getItem(int position) {
        // TODO Auto-generated method stub
        return resourceList.get(position);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        LayoutInflater inflate = ((Activity) context).getLayoutInflater();
        View view = (View) inflate.inflate(R.layout.simple_list_item_2, null);
        Resource r = resourceList.get(position);
        TextView textView = (TextView) view.findViewById(R.id.resource_name_text);
        textView.setText(r.name);
        textView = (TextView) view.findViewById(R.id.resource_url_text);
        textView.setText(r.url);
//        textView = (TextView) view.findViewById(R.id.resource_unreadcount);
//        textView.setText(String.valueOf(r.getUnreadCount()));
        return view;
    }

}
